package com.example.flutter_bsbdj

import android.Manifest
import android.annotation.TargetApi
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.Log

import io.flutter.app.FlutterActivity
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugins.GeneratedPluginRegistrant

@TargetApi(Build.VERSION_CODES.DONUT)
class MainActivity: FlutterActivity() {

  val pers= arrayOf(
          Manifest.permission.WRITE_EXTERNAL_STORAGE,
          Manifest.permission.CAMERA,
          Manifest.permission.REQUEST_INSTALL_PACKAGES
  )

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    PermissionUtil.getPermission(pers,this)
    GeneratedPluginRegistrant.registerWith(this)

    MethodChannel(flutterView,"android_message").setMethodCallHandler { methodCall, result ->
      if(methodCall.method == "back_home"){
        Log.d("method_channel",methodCall.argument("action"))
        val home=Intent(Intent.ACTION_MAIN)
        home.flags=Intent.FLAG_ACTIVITY_CLEAR_TOP
        home.addCategory(Intent.CATEGORY_HOME)
        startActivity(home)
      }
    }
  }




}
